<%@ page import="java.net.URLEncoder" %>
<%@ page import="cn.myschool.service.AdminService" %>
<%@ page import="cn.myschool.entity.Admin" %><%--
  Created by IntelliJ IDEA.
  User: C
  Date: 2022/7/4
  Time: 10:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String ip=request.getRemoteHost();
    request.setCharacterEncoding("utf-8");
    String loginname=request.getParameter("loginname");
    String upass = request.getParameter("upass");
    Admin admin = AdminService.ME.login(loginname, upass);

    //if(loginname.startsWith("java78")&&upass.equals("123")){
    if(admin!=null){
        //信息存入cookie
        //URLEncoder.encode(loginname,"utf-8")
        Cookie cname=new Cookie("loginname",loginname);
        cname.setMaxAge(86400*7);//一周
        response.addCookie(cname);
        //
        session.setAttribute("USER_LOGIN",admin);
        //session.setAttribute("upass",upass);
        //request.getRequestDispatcher("welcome.jsp").forward(request,response);
        response.sendRedirect("welcome.jsp");
    }else {
        request.getRequestDispatcher("denglu.jsp").forward(request,response);
    }

%>
</body>
</html>
